package com.hyz.yuaiagent.app;

import com.hyz.yuaiagent.advisor.MyLoggerAdvisor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class LoveAppWithMCP {

    private final ChatClient chatClient;

    @Autowired
    private ToolCallbackProvider toolCallbackProvider;

    @Autowired
    public LoveAppWithMCP(ChatModel dascopeChatModel) {
        this.chatClient = ChatClient.builder(dascopeChatModel)
                .build();
    }

    public void doChatWithMCP(String msg, String chatId) {
        ChatResponse chatResponse = chatClient.prompt()
                .user(msg)
                .advisors(new MyLoggerAdvisor())
                .tools(toolCallbackProvider)
                .call()
                .chatResponse();

        log.info(chatResponse.getResult().getOutput().getText());

    }


}
